home *** CD-ROM | disk | FTP | other *** search
/ .net 2002 March / DotNetMagazine-Issue107-Coverdisc-NET107-02-03-PCMac.bin / pc / PC Software / picks / HTTrack / httrack-3.22-3.exe / {app} / src / htscore.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-11-17  |  11.6 KB  |  374 lines

  1. /* ------------------------------------------------------------ */
  2. /*
  3. HTTrack Website Copier, Offline Browser for Windows and Unix
  4. Copyright (C) Xavier Roche and other contributors
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20.  
  21. Important notes:
  22.  
  23. - We hereby ask people using this source NOT to use it in purpose of grabbing
  24. emails addresses, or collecting any other private information on persons.
  25. This would disgrace our work, and spoil the many hours we spent on it.
  26.  
  27.  
  28. Please visit our Website: http://www.httrack.com
  29. */
  30.  
  31.  
  32. /* ------------------------------------------------------------ */
  33. /* File: Main file .h                                           */
  34. /* Author: Xavier Roche                                         */
  35. /* ------------------------------------------------------------ */
  36.  
  37. // Fichier librairie .h
  38. #ifndef HTTRACK_DEFH
  39. #define HTTRACK_DEFH
  40.  
  41.  
  42. #include "htsglobal.h"
  43.  
  44. /* specific definitions */
  45. #include "htsbase.h"
  46. // Includes & dÈfinitions
  47. #include <stdio.h>
  48. #include <stdlib.h>
  49. #include <string.h>
  50. #include <sys/types.h>
  51. #include <sys/stat.h>
  52. #ifdef _WIN32
  53. #include <conio.h>
  54. #include <signal.h>
  55. #include <direct.h>
  56. #else
  57. #include <signal.h>
  58. #if HAVE_UNISTD_H
  59. #include <unistd.h>
  60. #endif
  61. #endif
  62. /* END specific definitions */
  63.  
  64.  
  65. // Include htslib.h for all types
  66. #include "htslib.h"
  67.  
  68. #include "htsopt.h"
  69.  
  70. // structure d'un lien
  71. typedef struct {
  72.   char firstblock;      // flag 1=premier malloc 
  73.   char link_import;     // lien importÈ ‡ la suite d'un moved - ne pas appliquer les rËgles classiques up/down
  74.   int depth;            // profondeur autorisÈe lien ; >0 forte 0=faible
  75.   int pass2;            // traiter aprËs les autres, seconde passe. si == -1, lien traitÈ en background
  76.   int premier;          // pointeur sur le premier lien qui a donnÈ lieu aux autres liens du domaine
  77.   int precedent;        // pointeur sur le lien qui a donnÈ lieu ‡ ce lien prÈcis
  78.   //int moved;          // pointeur sur moved
  79.   int retry;            // nombre de retry restants
  80.   int testmode;         // mode test uniquement, envoyer juste un head!
  81.   char* adr;            // adresse
  82.   char* fil;            // nom du fichier distant
  83.   char* sav;            // nom ‡ sauver sur disque (avec chemin Èventuel)
  84.   char* cod;            // chemin codebase Èventuel si classe java
  85.   char* former_adr;     // adresse initiale (avant Èventuel moved), peut Ítre nulle
  86.   char* former_fil;     // nom du fichier distant initial (avant Èventuel moved), peut Ítre nul
  87.   // pour optimisation:
  88. #if HTS_HASH
  89.   int hash_next[3];     // prochain lien avec mÍme valeur hash
  90. #else
  91.   int sav_len;          // taille de sav
  92. #endif
  93. } lien_url;
  94.  
  95. // chargement de fichiers en 'arriËre plan'
  96. typedef struct {
  97. #if DEBUG_CHECKINT
  98.   char magic;
  99. #endif
  100.   char url_adr[HTS_URLMAXSIZE*2];     // adresse
  101.   char url_fil[HTS_URLMAXSIZE*2];     // nom du fichier distant
  102.   char url_sav[HTS_URLMAXSIZE*2];     // nom ‡ sauver sur disque (avec chemin Èventuel)
  103.   char referer_adr[HTS_URLMAXSIZE*2]; // adresse host page referer
  104.   char referer_fil[HTS_URLMAXSIZE*2]; // fichier page referer
  105.   char location_buffer[HTS_URLMAXSIZE*2];  // "location" en cas de "moved" (302,..)
  106.   char tmpfile[HTS_URLMAXSIZE*2];     // nom ‡ sauver temporairement (compressÈ)
  107.   char send_too[1024];    // donnÈes ‡ envoyer en mÍme temps que le header
  108.   int status;           // status (-1=non utilisÈ, 0: prÍt, >0: opÈration en cours)
  109.   int testmode;         // mode de test
  110.   int timeout;            // gÈrer des timeouts? (!=0  : nombre de secondes)
  111.   TStamp timeout_refresh; // si oui, time refresh
  112.   int rateout;            // timeout refresh? (!=0 : taux minimum tolÈrÈ en octets/s)
  113.   TStamp rateout_time;    // si oui, date de dÈpart
  114.   LLint maxfile_nonhtml;  // taille max d'un fichier non html
  115.   LLint maxfile_html;     // idem pour un ficheir html
  116.   htsblk r;               // structure htsblk de chaque objet en background 
  117.   int is_update;          // mode update
  118.   int head_request;       // requËte HEAD?
  119.   LLint range_req_size;   // range utilisÈ
  120.   //
  121.   int http11;             // L'en tÍte doit Ítre signÈ HTTP/1.1 et non HTTP/1.0
  122.   int is_chunk;           // chunk?
  123.   char* chunk_adr;        // adresse chunk en cours de chargement
  124.   LLint chunk_size;       // taille chunk en cours de chargement
  125.   LLint compressed_size;  // taille compressÈs (stats uniquement)
  126.   //
  127.   int* pass2_ptr;         // pointeur sur liens[ptr]->pass2
  128.   //
  129.   char info[256];         // Èventuel status pour le ftp
  130.   int stop_ftp;           // flag stop pour ftp
  131. #if DEBUG_CHECKINT
  132.   char magic2;
  133. #endif
  134. } lien_back;
  135.  
  136. // cache
  137. typedef struct {
  138.   int version;        // 0 ou 1
  139.   /* */
  140.   int type;
  141.   int ro;
  142.   FILE *dat,*ndx,*olddat;
  143.   char *use;      // liste des adr+fil
  144.   FILE *lst;      // liste des fichiers pour la "purge"
  145.   FILE *txt;      // liste des fichiers (info)
  146.   char lastmodified[256];
  147.   // HASH
  148.   void* hashtable;
  149.   // fichiers log optionnels
  150.   FILE* log;
  151.   FILE* errlog;
  152.   // variables
  153.   int ptr_ant;      // pointeur pour anticiper
  154.   int ptr_last;     // pointeur pour anticiper
  155. } cache_back;
  156.  
  157. typedef struct {
  158.   lien_url** liens;                     // pointeur sur liens
  159.   int max_lien;                         // indice le plus grand rencontrÈ
  160.   int hash[3][HTS_HASH_SIZE];           // tables pour sav/adr-fil/former_adr-former_fil
  161. } hash_struct;
  162.  
  163. #if HTS_HASH
  164. #else
  165. #define hash_write(A,B)
  166. #endif
  167.  
  168. typedef struct {
  169.   FILE* lst;
  170.   char path[HTS_URLMAXSIZE*2];
  171. } filecreate_params;
  172.  
  173. // Fonctions
  174.  
  175. // INCLUDES .H PARTIES DE CODE HTTRACK
  176.  
  177. // routine main
  178. #include "htscoremain.h"
  179.  
  180. // divers outils pour httrack.c
  181. #include "htstools.h"
  182.  
  183. // aide pour la version en ligne de commande
  184. #include "htshelp.h"
  185.  
  186. // gÈnÈration du nom de fichier ‡ sauver
  187. #include "htsname.h"
  188.  
  189. // gestion ftp
  190. #include "htsftp.h"
  191.  
  192. // routine parser java
  193. #include "htsjava.h"
  194.  
  195. // gestion interception d'URL
  196. #include "htscatchurl.h"
  197.  
  198. // gestion robots.txt
  199. #include "htsrobots.h"
  200.  
  201. // routines d'acceptation de liens
  202. #include "htswizard.h"
  203.  
  204. // routines de regexp
  205. #include "htsfilters.h"
  206.  
  207. // gestion backing
  208. #include "htsback.h"
  209.  
  210. // gestion cache
  211. #include "htscache.h"
  212.  
  213. // gestion hashage
  214. #include "htshash.h"
  215. #include "htsinthash.h"
  216.  
  217. // gestion rÈentrance
  218. #include "htsnostatic.h"
  219.  
  220. // infos console
  221. #if HTS_ANALYSTE_CONSOLE
  222. #include "httrack.h"
  223. #endif
  224.  
  225. #include "htsdefines.h"
  226.  
  227. #include "hts-indextmpl.h"
  228.  
  229. // INCLUDES .H PARTIES DE CODE HTTRACK
  230.  
  231. //
  232.  
  233. /*
  234. typedef void  (* t_hts_htmlcheck_init)(void);
  235. typedef void  (* t_hts_htmlcheck_uninit)(void);
  236. typedef int   (* t_hts_htmlcheck_start)(httrackp* opt);
  237. typedef int   (* t_hts_htmlcheck_end)(void);
  238. typedef int   (* t_hts_htmlcheck_chopt)(httrackp* opt);
  239. typedef int   (* t_hts_htmlcheck)(char* html,int len,char* url_adresse,char* url_fichier);
  240. typedef char* (* t_hts_htmlcheck_query)(char* question);
  241. typedef char* (* t_hts_htmlcheck_query2)(char* question);
  242. typedef char* (* t_hts_htmlcheck_query3)(char* question);
  243. typedef int   (* t_hts_htmlcheck_loop)(lien_back* back,int back_max,int back_index,int lien_tot,int lien_ntot,LLint stat_bytes,LLint stat_bytes_recv,int stat_time,int stat_nsocket, LLint stat_written, int stat_updated, int stat_errors, int irate, int nbk );
  244. typedef int   (* t_hts_htmlcheck_check)(char* adr,char* fil,int status);
  245. typedef void  (* t_hts_htmlcheck_pause)(char* lockfile);
  246. */
  247.  
  248. // demande d'interaction avec le shell
  249. #if HTS_ANALYSTE
  250. //char HTbuff[1024];
  251. /*
  252. extern t_hts_htmlcheck_init    hts_htmlcheck_init;
  253. extern t_hts_htmlcheck_uninit  hts_htmlcheck_uninit;
  254. extern t_hts_htmlcheck_start   hts_htmlcheck_start;
  255. extern t_hts_htmlcheck_end     hts_htmlcheck_end;
  256. extern t_hts_htmlcheck_chopt   hts_htmlcheck_chopt;
  257. extern t_hts_htmlcheck         hts_htmlcheck;
  258. extern t_hts_htmlcheck_query   hts_htmlcheck_query;
  259. extern t_hts_htmlcheck_query2  hts_htmlcheck_query2;
  260. extern t_hts_htmlcheck_query3  hts_htmlcheck_query3;
  261. extern t_hts_htmlcheck_loop    hts_htmlcheck_loop;
  262. extern t_hts_htmlcheck_check   hts_htmlcheck_check;
  263. extern t_hts_htmlcheck_pause   hts_htmlcheck_pause;
  264. */
  265. //
  266. HTSEXT_API int hts_is_parsing(int flag);
  267. HTSEXT_API int hts_is_testing(void);
  268. HTSEXT_API int hts_is_exiting(void);
  269. HTSEXT_API int hts_setopt(httrackp* opt);
  270. HTSEXT_API int hts_addurl(char** url);
  271. HTSEXT_API int hts_resetaddurl(void);
  272. HTSEXT_API int copy_htsopt(httrackp* from,httrackp* to);
  273. HTSEXT_API char* hts_errmsg(void);
  274. HTSEXT_API int hts_setpause(int);      // pause transfer
  275. HTSEXT_API int hts_request_stop(int force);
  276. //
  277. HTSEXT_API char* hts_cancel_file(char * s);
  278. HTSEXT_API void hts_cancel_test(void);
  279. HTSEXT_API void hts_cancel_parsing(void);
  280. //
  281. // Variables globales
  282. extern int _hts_in_html_parsing;
  283. extern int _hts_in_html_done;  // % rÈalisÈs
  284. extern int _hts_in_html_poll;  // parsing
  285. extern char _hts_errmsg[1100];
  286. extern int _hts_setpause;
  287. //extern httrackp* _hts_setopt;
  288. extern char** _hts_addurl;
  289. extern int _hts_cancel;
  290. #endif
  291.  
  292.  
  293.  
  294. //
  295.  
  296.  
  297. //int httpmirror(char* url,int level,httrackp opt);
  298. int httpmirror(char* url1,httrackp* opt);
  299. int filesave(char* adr,int len,char* s);
  300. int engine_stats(void);
  301. void host_ban(httrackp* opt,lien_url** liens,int ptr,int lien_tot,lien_back* back,int back_max,char** filters,int filter_max,int* filptr,char* host);
  302. FILE* filecreate(char* s);
  303. int filecreateempty(char* filename);
  304. int filenote(char* s,filecreate_params* params);
  305. HTS_INLINE void usercommand(int exe,char* cmd,char* file);
  306. void usercommand_exe(char* cmd,char* file);
  307. void* structcheck_init(int init);
  308. int filters_init(char*** ptrfilters, int maxfilter, int filterinc);
  309. HTSEXT_API int structcheck(char* s);
  310. HTS_INLINE int fspc(FILE* fp,char* type);
  311. char* next_token(char* p,int flag);
  312. //
  313. char* readfile(char* fil);
  314. char* readfile_or(char* fil,char* defaultdata);
  315. #if 0
  316. void check_rate(TStamp stat_timestart,int maxrate);
  317. #endif
  318.  
  319. // liens
  320. int liens_record(char* adr,char* fil,char* save,char* former_adr,char* former_fil,char* codebase);
  321.  
  322.  
  323. // backing, routines externes
  324. int back_fill(lien_back* back,int back_max,httrackp* opt,cache_back* cache,lien_url** liens,int ptr,int numero_passe,int lien_tot);
  325. int backlinks_done(lien_url** liens,int lien_tot,int ptr);
  326. int back_fillmax(lien_back* back,int back_max,httrackp* opt,cache_back* cache,lien_url** liens,int ptr,int numero_passe,int lien_tot);
  327.  
  328. // cancel file
  329. #if HTS_ANALYSTE
  330. HTSEXT_API char* hts_cancel_file(char * s);
  331. HTSEXT_API void hts_cancel_test(void);
  332. HTSEXT_API void hts_cancel_parsing(void);
  333. #endif
  334.  
  335. int ask_continue(void);
  336. int nombre_digit(int n);
  337.  
  338. // Java
  339. #if 0
  340. int hts_add_file(char* file,int file_position);
  341. #endif
  342.  
  343. // Polling
  344. #if HTS_POLL
  345. HTS_INLINE int check_flot(T_SOC s);
  346. HTS_INLINE int check_stdin(void);
  347. int read_stdin(char* s,int max);
  348. #endif
  349.  
  350. httrackp* hts_declareoptbuffer(httrackp* optdecl);
  351. void sig_finish( int code );     // finir et quitter
  352. void sig_term( int code );       // quitter
  353. #if HTS_WIN
  354. void sig_ask( int code );        // demander
  355. #else
  356. void sig_back( int code );       // ignorer et mettre en backing 
  357. void sig_ask( int code );        // demander
  358. void sig_ignore( int code );     // ignorer signal
  359. void sig_brpipe( int code );     // treat if necessary
  360. void sig_doback(int);            // mettre en arriËre plan
  361. #endif
  362.  
  363. /* external modules */
  364. int htsAddLink(htsmoduleStruct* str, char* link);
  365.  
  366. // Void
  367. void voidf(void);
  368.  
  369. #define HTS_TOPINDEX "TOP_INDEX_HTTRACK"
  370.  
  371. #endif
  372.  
  373.  
  374.